package edu.whu.xterm.http;

import java.io.InputStream;
import java.util.concurrent.Callable;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;

public class PageStringWorker implements Callable<InputStream> {

	private String url;

	private HttpClient mClient;

	public PageStringWorker(HttpClient client, String url) {
		mClient = client;
		this.url = url;
	}

	@Override
	public InputStream call() throws Exception {

		HttpResponse response = mClient.execute(new HttpGet(url));
		StatusLine sl;
		if (response == null || (sl = response.getStatusLine()) == null)
			return null;
		final int statusCode = sl.getStatusCode();
		if (HttpStatus.SC_OK != statusCode) {
			return null;
		}
		return response.getEntity().getContent();
	}
}
